<?php
/**
 * Created by PhpStorm.
 * User: LiuJiaJun
 * Date: 2019/1/13
 * Time: 19:19
 */

namespace api\storage\service\inventory;


use api\storage\common\Constant;
use api\storage\model\ReelsModel;
use api\storage\model\ShelvesModel;
use api\storage\service\SocketService;

class WhiteShelfInventoryService extends BaseShelfInventoryService
{
    protected function afterHandleLightOff($seatId, $storageUuid)
    {
        SocketService::send($seatId, $storageUuid, Constant::TURN_OFF_LIGHT);
    }

    protected function getReels($code, $storageUuid)
    {
        $reelsModel = new ReelsModel();
        $reels = $reelsModel->queryByShelfCodeWithSeat($code, $storageUuid)->toArray();
        $seatIds = array_column($reels, 'seatId');
        SocketService::send($seatIds, $storageUuid, Constant::TURN_ON_GREEN);
        //设置flag的占用
        $this->remakeFlag($code,$storageUuid,true);
        return [
            'reels' => $reels,
            'seatId' => $seatIds
        ];
    }
    protected function remakeFlag($code, $storageUuid, $isOccupy)
    {
        $shelvesModel = new ShelvesModel();
        $flag = $isOccupy ? 1 : 0;
        //A01 ,A01L,A01L1有这三种情况，取前三位即可
        $code = substr($code,0,3);
        $result = $shelvesModel->updateFlag($code, $storageUuid, $flag);
        return $result !== false ? true : false;
    }

}